classdef Crystal < handle
  %CRYSTAL Summary of this class goes here
  %   Detailed explanation goes here
  
  properties
    Basis;
    Lattice;
    Positions;
    LatticeVectors;
    Atoms;
  end
  
  properties(Dependent)
    NumAtomTypes;
    AtomTypes;
    NumAtoms;
    NumDimensions;
  end
  
  methods
    function co = Crystal(lattice, basis)
      co.Lattice = lattice;
      co.Basis = basis;
      co.Positions = basis.BasisVectors*lattice.LatticeVectors;
      co.Atoms = basis.Atoms;
      co.LatticeVectors = lattice.LatticeVectors;
    end
    
    function [numDimensions] = get.NumDimensions(co)
      numDimensions = size(co.LatticeVectors, 1);
    end
    
    function [numAtoms] = get.NumAtoms(co)
      numAtoms = zeros(co.NumAtomTypes, 1);
      for i = 1:co.NumAtomTypes
        index = find(strcmp(co.Atoms, co.AtomTypes(i)));
        numAtoms(i) = length(index);
      end
    end
    
    function [atomTypes] = get.AtomTypes(co)
      atomTypes = unique(co.Atoms);
    end

    function [numAtomTypes] = get.NumAtomTypes(co)
      numAtomTypes = length(co.AtomTypes);
    end
    
  end
  
  methods(Static)
    test();
    
    function obj = create_hematite_rhombohedral()
      bo = Basis.create_hematite_rhombohedral;
      lo = Lattice.create_hematite_rhombohedral();      
      obj = Crystal(lo, bo);
    end
  end
end

